package pcb.views.library 
{
	import flash.display.MovieClip;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import com.intel.utils.TextRender;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	public class Checkbox extends EventDispatcher
	{
		private var _librarySymbol:MovieClip;
		private var _labelText:String = "";
		private var _selected:Boolean = false;
		private var _enabled:Boolean = true;
		
		
		public function Checkbox(symbol:MovieClip, title:String) 
		{
			_librarySymbol = symbol;
			this.label = title;
			init();
		}
		
		protected function init():void 
		{
			_librarySymbol.addEventListener(MouseEvent.CLICK, onClick);
			
		}
		
		protected function onClick(event:MouseEvent):void
		{
			selected = !_selected;
			
			this.dispatchEvent(event);
		}
		
		public function draw():void 
		{
			if (_enabled && this.selected) {
				_librarySymbol.gotoAndStop("selected");
			}else if (!_enabled && this.selected) {
				_librarySymbol.gotoAndStop("selected_dull");
			}else if (_enabled && !this.selected){
				_librarySymbol.gotoAndStop("deselected");
			}else if (!_enabled && !this.selected) {
				_librarySymbol.gotoAndStop("deselected_dull");
			}
						
			TextRender.createLabel(_librarySymbol.chkTxt, this.label);
			
			/*if (this.selected) {
				_librarySymbol.gotoAndStop("selected");
			}else {
				_librarySymbol.gotoAndStop("deselected");
			}*/
		}
		
		/**
		 * Sets / gets the label text shown on this CheckBox.
		 */
		public function set label(str:String):void
		{			
			_labelText = str;
			draw();
		}
		public function get label():String
		{
			return _labelText;
		}
		
		/**
		 * Sets / gets the selected state of this CheckBox.
		 */
		public function set selected(s:Boolean):void
		{
			_selected = s;
			draw();
		}
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function enableChk(boo:Boolean):void 
		{
			_enabled = boo;
			draw();
		}

		
	}
	
}